package liangtWorkSpace.netty;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpServerChannel;

/**
 * @ClassName HttpServer
 * @Description : httpServer netty
 * @Author : LiangT
 * @Date : 2020/7/4 20:37
 */
public class HttpServer {

    public static void main(String[] args) {
        HttpServer httpServer = new HttpServer();
        httpServer.httpServer();
    }

    public void httpServer(){
        //构建两个线程池
        EventLoopGroup bossrGroup = new NioEventLoopGroup();
        EventLoopGroup workeGroup = new NioEventLoopGroup();
        try {
            ServerBootstrap bootstrap = new ServerBootstrap();
            bootstrap.group(bossrGroup,workeGroup)
                    .channel(NioSctpServerChannel.class)
                    .childHandler(new HttpServerInitializer());
            ChannelFuture future = bootstrap.bind(8088).sync();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            //结束时，释放线程池
            bossrGroup.shutdownGracefully();
            workeGroup.shutdownGracefully();
        }
    }
}
